home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / boosters.arc / COPYSTR.ASM < prev    next >
Assembly Source File  |  1985-11-16  |  1KB  |  69 lines

  1. ;**************************************************
  2. ;       type
  3. ;           AnyString = string[255];
  4. ;       var
  5. ;           S : AnyString;
  6. ;           N : integer;
  7. ;
  8. ;       Function COPYSTR (S : AnyString;
  9. ;                         N : Integer) : AnyString;
  10. ;
  11. ;       Returns N concatenated copies of S.
  12. ;
  13. ;**************************************************
  14. COPYSTR proc    near
  15.         push    bp
  16.     mov    bp,sp
  17.     push    ds
  18. ;
  19.     mov    cx,[bp+4]    ; N into CX
  20.     cmp    cx,0
  21.     jg    AboveZ
  22.     mov    [bp+262],0
  23.     jmp    return
  24. AboveZ: mov    dl,[bp+6]    ; Len of S;
  25.     xor    dh,dh
  26. ;
  27.     push    cx
  28.     mov    ax,dx
  29.     dec    cx
  30.     cmp    cx,0
  31.     je    N001
  32. ;
  33. ;***    Length of Result = N x Length(S)
  34. ;
  35. Adder:    add    ax,dx        ; Compute Length
  36.     loop    Adder        ; of result
  37. ;
  38. N001:    mov    cx,dx
  39.     pop    dx
  40.     cmp    ax,255
  41.     jbe    N002
  42.     mov    ax,255
  43.     jmp    N003
  44. N002:    cmp    al,0
  45.     jae    n003
  46.     xor    ax,ax
  47. N003:    mov    [bp+262],al    ; L'Result
  48.     cmp    al,0
  49.     je    return
  50. ;
  51.     mov    bx,ss
  52.     mov    es,bx
  53.     mov    ds,bx
  54.     lea    di,[bp+263]
  55.     lea    si,[bp+7]
  56.         cld
  57. COPYS:    push    cx
  58.     push    si
  59. rep    movsb
  60.     pop    si
  61.     pop    cx
  62.     dec    dx
  63.     jnz    COPYS
  64. ;
  65. RETURN    pop    ds
  66.         mov     sp,bp
  67.         pop     bp
  68.         ret     258
  69. COPYSTR endp